package com.example.douyin.friends;

import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.Observer;

import android.os.Bundle;
import android.view.View;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.blankj.utilcode.util.ToastUtils;
import com.example.douyin.R;
import com.example.douyin.databinding.ActivityAddFriendBinding;
import com.example.lib_base_mvvm.baseMVVM.BaseView.BaseActivity;
@Route(path = "/app/AddFriendActivity")
public class AddFriendActivity extends BaseActivity<ActivityAddFriendBinding,FriendsViewModel> {


    @Override
    public int bindLayout() {
        return R.layout.activity_add_friend;
    }

    @Override
    public void initView() {
        dataBinding.add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                viewModel.addFriend(dataBinding.etName.getText().toString(),dataBinding.etReason.getText().toString());
            }
        });
    }

    @Override
    public void initData() {
        viewModel.addSuccess.observe(this, new Observer<String>() {
            @Override
            public void onChanged(String s) {
                ToastUtils.showLong(s);
                finish();
            }
        });
        viewModel.addFail.observe(this, new Observer<String>() {
            @Override
            public void onChanged(String s) {
                ToastUtils.showLong(s);
            }
        });
    }

    @Override
    public Class<FriendsViewModel> getViewModel() {
        return FriendsViewModel.class;
    }
}